package com.yang.controller;


import com.yang.constant.ConfiConstant;
import com.yang.dao.MyOrderDao;
import com.yang.pojo.MyOrderDto;
import org.jboss.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class MyOrderController {
    private static Logger logger = Logger.getLogger(MyOrderController.class);

    @Resource
    MyOrderDao myOrderDao;

    @RequestMapping(produces = "application/json;charset=UTF-8",value = "customer/select_my_order",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> selectMyOrder(HttpServletRequest request){
        Map<String,Object> map = new HashMap<String, Object>();
        Long userId = (Long)request.getSession().getAttribute("id");
        if(userId == null){
            map.put("status","error");
            map.put("info","网络出错！");
        }

        List<MyOrderDto> finishMyOrderDto = myOrderDao.selectMyorder(userId, ConfiConstant.HISTORICAL_RELATIONSHIP,ConfiConstant.HOMEOWNER);
        List<MyOrderDto> unfinisMyOrderDto = myOrderDao.selectMyorder(userId,ConfiConstant.UNHISTORICAL_RELATIONSHIP,ConfiConstant.HOMEOWNER);
        map.put("status","succeed");
        map.put("finishMyOrderDto",finishMyOrderDto);
        map.put("unfinisMyOrderDto",unfinisMyOrderDto);
        return map;
    }
}
